package com.hxd.otc.module.my.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.my.bean.BaseListBean;
import com.hxd.otc.module.my.bean.ExchangeRecordBean;
import com.hxd.otc.module.my.contract.ExchangeRecoderContract;
import com.hxd.otc.module.my.model.ExchangeModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.ArrayList;

/**
 * 作  者 :  zjl
 * 时  间 :  2018/6/4 17:02
 * 描  述 :  ${所有订单页面P}
 */
public class ExchangeRecordPresenter extends BasePresenter<ExchangeRecoderContract.View> implements ExchangeRecoderContract.Presenter {

    ExchangeModel model;

    public ExchangeRecordPresenter(ExchangeRecoderContract.View view) {
        super(view);
        model = ExchangeModel.getInstance();
    }

    @Override
    public void doLoadData(String showCount, String currentPage) {
        model.exchangeList(showCount, currentPage, new BaseObserver<BaseListBean<ExchangeRecordBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull BaseListBean<ExchangeRecordBean> exchangeRecordBeans) {
                doSetAdapter(exchangeRecordBeans.getList());
                doShowNoMore();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
                mView.onError(errType);
                doShowNoMore();
            }
        }, mView.<BaseBean<BaseListBean<ExchangeRecordBean>>>bindAutoDispose());
    }

    @Override
    public void doShowNoMore() {
        mView.onShowNoMore();
    }

    @Override
    public void doSetAdapter(ArrayList<ExchangeRecordBean> beans) {
        mView.onSetAdapter(beans);
        mView.onShowNoMore();
    }
}
